package com.fr.data.core.db.dialect;

import com.fr.base.StringUtils;

public class MSSQL2000Dialect extends MSSQLDialect
{
  public String columnType2SQL(int paramInt, String paramString)
  {
    switch (paramInt)
    {
    case 2004:
      return "image";
    case 91:
      return "datetime";
    case 92:
      return "datetime";
    case 93:
      return "datetime";
    case 8:
      return "float";
    case -5:
      return "numeric(" + paramString + ")";
    case -7:
      return "varchar(1)";
    case 2005:
      return "text";
    case 4:
      return "int";
    case 12:
      return "varchar(" + paramString + ")";
    case -3:
      return "varchar(" + paramString + ")";
    case 7:
      return "float";
    case -6:
      return "smallint";
    case 3:
      return "decimal(" + paramString + ")";
    case 2:
      return "numeric(" + paramString + ")";
    case 1:
      return "char(" + paramString + ")";
    case -1:
      return "ntext";
    case -4:
      return "image";
    case -2:
      return "binary(" + paramString + ")";
    }
    return TypeUtils.getTypeName(paramInt);
  }

  public String getCountSql(String paramString)
  {
    if (StringUtils.isBlank(paramString))
      return null;
    String str = paramString.toUpperCase();
    int i = str.lastIndexOf("ORDER");
    int j = str.lastIndexOf("BY");
    if ((j > i) && (i > 0) && (StringUtils.isBlank(str.substring(i + 5, j))) && (str.substring(j).indexOf(")") < 0))
      return "SELECT COUNT(*) FROM (" + paramString.substring(0, i) + ") t";
    return "SELECT COUNT(*) FROM (" + paramString + ") t";
  }
}